/**
 * Bakalarska prace - Inteligentni budik
 * @package sleepCatcher
 * @file FormAlarmName.cpp
 * @author Jan Pesava - xpesav00
 * @email xpesav00@stud.fit.vutbr.cz
 * @date 24. 12. 2011
 */

#include "forms/FormAlarmName.h"
#include "SCFormManager.h"
#include "SCTranslator.h"

FormAlarmName::FormAlarmName()
{
}

FormAlarmName::~FormAlarmName()
{
}


bool
FormAlarmName::Initialize()
{
	Construct(L"IDF_ALARM_NAME");
	return true;
}

result
FormAlarmName::OnInitializing(void)
{
	result r = E_SUCCESS;

	//language
	this->SetTitleText(SCTranslator::GetText("IDS_ALARMSNAME_TITLE"));

	this->pAlarmName = static_cast<EditField*>(GetControl("IDC_EDITFIELD_NAME"));
	this->pAlarmName->SetOverlayKeypadCommandButton(COMMAND_BUTTON_POSITION_LEFT, SCTranslator::GetText("IDS_ALARMS_SAVE"), IDA_ALARM_CONFIRM);
	this->pAlarmName->SetOverlayKeypadCommandButton(COMMAND_BUTTON_POSITION_RIGHT, SCTranslator::GetText("IDS_ALARMS_BACK"), IDA_ALARM_CANCEL);
	this->pAlarmName->AddActionEventListener(*this);
	this->pAlarmName->ShowKeypad();

	return r;
}

result
FormAlarmName::OnTerminating(void)
{
	result r = E_SUCCESS;
	return r;
}

void
FormAlarmName::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
{
	ArrayList* pParams;

	switch(actionId)
	{
		case IDA_ALARM_CONFIRM:
			this->pAlarm->SetName(pAlarmName->GetText());
			pParams = new ArrayList();
			pParams->Add(*this->pAlarm);
			SCFormManager::SwitchToForm(SCFormManager::IDF_ALARM_SET, false, pParams, SCFormManager::NO_SLIDE);
			pParams->RemoveAll();
			delete pParams;
			break;
		case IDA_ALARM_CANCEL:
			pParams = new ArrayList();
			pParams->Add(*this->pAlarm);
			SCFormManager::SwitchToForm(SCFormManager::IDF_ALARM_SET, false, pParams, SCFormManager::NO_SLIDE);
			pParams->RemoveAll();
			delete pParams;
			break;
	}
}

int
FormAlarmName::GetFormId()
{
	return SCFormManager::IDF_ALARM_NAME;
}

void
FormAlarmName::SetAlarm(SCAlarm* pAlarm)
{
	this->pAlarm = pAlarm;
}

SCAlarm*
FormAlarmName::GetAlarm()
{
	return this->pAlarm;
}

void
FormAlarmName::Update()
{
	if(this->pAlarm != NULL)
	{
		this->pAlarmName->SetText(pAlarm->GetName());
	}

	//show keypad
	this->pAlarmName->ShowKeypad();
}

void
FormAlarmName::Redraw()
{
	this->Update();
	RequestRedraw(true);
}
